package com.cmc.cloud.cmclink.doc.controller.admin.si;

import java.util.Collection;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.cmc.cloud.cmclink.doc.api.document.emums.ExImTypeEnum;
import com.cmc.cloud.cmclink.doc.vo.confirmnoticevo.ConfirmNoticeRejectReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.operatelog.core.annotations.OperateLog;
import com.cmes.framework.operatelog.core.enums.OperateTypeEnum;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.cmc.cloud.cmclink.doc.constants.CommonConstants;
import com.cmc.cloud.cmclink.doc.service.si.ConfirmNoticeService;
import com.cmc.cloud.cmclink.doc.vo.confirmnoticevo.ConfirmNoticeDetailRespVO;
import com.cmc.cloud.cmclink.doc.vo.confirmnoticevo.ConfirmNoticePageReqVO;
import com.cmc.cloud.cmclink.doc.vo.confirmnoticevo.ConfirmNoticeRespVO;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 确认装货港更改通知前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 确认装货港更改通知")
@RestController
@Validated
@RequestMapping("/doc/v1/confirm-notice")
public class ConfirmNoticeController {

    @Resource
    private ConfirmNoticeService confirmNoticeService;

    @Operation(summary = "确认装货港更改通知详情")
    @OperateLog(type = OperateTypeEnum.GET)
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission({'doc:pod:detail','doc:SIChangeApprove:preview','doc:SIChangeApply:preview'})")
    public CommonResult<ConfirmNoticeDetailRespVO> getConfirmNotice(@PathVariable("id") Long id) {
        ConfirmNoticeDetailRespVO resp = confirmNoticeService.getConfirmNotice(id);
        return CommonResult.success(resp);
    }

    @Operation(summary = "确认装货港更改通知分页")
    @OperateLog(type = OperateTypeEnum.GET)
    @PostMapping("/page")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:pod:noticed')")
    public CommonResult<PageResult<ConfirmNoticeRespVO>>
    getConfirmNoticePage(@Valid @RequestBody ConfirmNoticePageReqVO pageVO) {
        PageResult<ConfirmNoticeRespVO> pageResult =
                confirmNoticeService.getConfirmNoticePage(pageVO, ExImTypeEnum.IM.getValue());
        return CommonResult.success(new PageResult<>(pageResult.getList(), pageResult.getTotal()));
    }

    @Operation(summary = "si更改装货港审核信息")
    @OperateLog(type = OperateTypeEnum.UPDATE)
    @PostMapping("/page/ex")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission({'doc:SIChangeApprove:search','doc:SIChangeApply:search'})")
    public CommonResult<PageResult<ConfirmNoticeRespVO>>
    getConfirmNoticeExPage(@Valid @RequestBody ConfirmNoticePageReqVO pageVO) {
        PageResult<ConfirmNoticeRespVO> pageResult =
                confirmNoticeService.getConfirmNoticePage(pageVO, ExImTypeEnum.EX.getValue());
        return CommonResult.success(new PageResult<>(pageResult.getList(), pageResult.getTotal()));
    }

    @Operation(summary = "确认装货港更改通知标记")
    @OperateLog(type = OperateTypeEnum.UPDATE)
    @GetMapping("/note/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<String> noteConfirmNotice(@PathVariable("id") Long id) {
        confirmNoticeService.noteConfirmNotice(id);
        return CommonResult.success(CommonConstants.RESPONSE_SUCCESS);
    }

    @Operation(summary = "确认装货港更改通知批量标记")
    @OperateLog(type = OperateTypeEnum.UPDATE)
    @GetMapping("/batch/note")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('doc:pod:noticed')")
    public CommonResult<String> noteBatchConfirmNotice(@RequestParam("ids") Collection<Long> ids) {
        confirmNoticeService.noteBatchConfirmNotice(ids);
        return CommonResult.success(CommonConstants.RESPONSE_SUCCESS);
    }

    /**
     * 通过通知
     *
     * @param confirmNoticeRejectReqVO 通知主表主键
     * @return void
     */
    @Operation(summary = "审核通过")
    @OperateLog(type = OperateTypeEnum.UPDATE)
    @PostMapping("/approveNotice")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission({'doc:pod:single-approve','doc:SIChangeApprove:approve'})")
    public CommonResult<Void> approveNotice(@RequestBody @Valid ConfirmNoticeRejectReqVO confirmNoticeRejectReqVO, HttpServletResponse httpServletResponse) {
        confirmNoticeRejectReqVO.setResponse(httpServletResponse);
        confirmNoticeService.approveNotice(confirmNoticeRejectReqVO);
        return CommonResult.success();
    }

    /**
     * 拒绝通知
     *
     * @param confirmNoticeRejectReqVO
     * @return void
     */
    @Operation(summary = "审核拒绝")
    @OperateLog(type = OperateTypeEnum.UPDATE)
    @PostMapping("/rejectNotice")
    @PreAuthorize("@ss.hasPermission({'doc:pod:single-reject','doc:SIChangeApprove:reject'})")
    public CommonResult<Void> rejectNotice(@RequestBody @Valid ConfirmNoticeRejectReqVO confirmNoticeRejectReqVO) {
        confirmNoticeService.rejectNotice(confirmNoticeRejectReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "申请人取消审核")
    @OperateLog(type = OperateTypeEnum.UPDATE)
    @PostMapping("/cancelNotice/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<Void>  cancelNotice(@PathVariable("id") Long id){
        confirmNoticeService.cancelNotice(id);
        return CommonResult.success();
    }

}
